﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Jy123.Web.Manage
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                SqlParameter[] parameters = {
                    new SqlParameter("@MName", SqlDbType.VarChar,20),
                    new SqlParameter("@Password", SqlDbType.VarChar,32)};
                parameters[0].Value = txtName.Value;
                parameters[1].Value = Jy123.DBUtility.DESEncrypt.Md5(password.Value, true);

                Jy123.Model.Manage_Main manage = new Jy123.Model.Manage_Main();
                manage.ID = Convert.ToInt32(Jy123.DBUtility.DbHelperSQL.GetSingle("select [ID] from Manage_Main where MName=@MName and Password=@Password", parameters));
                if (manage.ID > 0)
                {
                    manage = new BLL.Manage_Main().GetModel(manage.ID);
                    manage.LoginIP = Common.Public.GetClientIP();
                    manage.LastLogin = DateTime.Now;
                    new BLL.Manage_Main().Update(manage); 
                    Session["SManage"] = manage;
                    Response.Redirect("index.html", false);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch //(Exception ex)
            {
                txtName.Value = "账号";
                warError.Visible = true;
            }
        }
    }
}
